/*
 * SongTransferable.java
 *
 * Created on September 15, 2006, 2:24 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package com.bff.mpd.musicjukebox.lib;

import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import org.bff.javampd.objects.MPDSong;

/**
 *
 * @author bfindeisen
 */
public class SongTransferable implements Transferable, ClipboardOwner {

    private MPDSong song;
    public static DataFlavor songFlavor = null;
    public static DataFlavor localSongFlavor = null;
    

    static {
        try {
            songFlavor = new DataFlavor(org.bff.javampd.objects.MPDSong.class,
                    "Non local Song");
            localSongFlavor = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType +
                    "; class=com.bff.music.Song",
                    "Local Song");
        } catch (Exception e) {
            System.err.println(e);
        }
    }
    public static final DataFlavor[] flavors = {
        songFlavor,
        localSongFlavor
    };
    private static final List flavorList = Arrays.asList(flavors);

    /** Creates a new instance of SongTransferable */
    public SongTransferable(MPDSong song) {
        this.song = song;
    }

    @Override
    public DataFlavor[] getTransferDataFlavors() {
        return (flavors);
    }

    @Override
    public boolean isDataFlavorSupported(DataFlavor flavor) {
        return (flavorList.contains(flavor));
    }

    @Override
    public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
        if (flavor.equals(songFlavor)) {
            return (this.song);
        } else if (flavor.equals(localSongFlavor)) {
            return this.song;

        } else if (flavor.equals(DataFlavor.stringFlavor)) {
            return (this.song.getArtist() + " - " + this.song.getAlbum() + " - " + this.song.getTitle());
        } else {
            throw new UnsupportedFlavorException(flavor);
        }
    }

    @Override
    public void lostOwnership(Clipboard clipboard, Transferable contents) {
    }
}
